"""项目配置"""

import os
from datetime import timedelta
from dataclasses import dataclass
from flask_uploads import UploadSet
from dotenv import load_dotenv

load_dotenv()

# 从环境变量读取数据库配置信息
USER = os.getenv("MYSQL_USER_NAME")
PWD = os.getenv("MYSQL_USER_PASSWORD")
HOST = os.getenv("MYSQL_HOSTNAME")
PORT = os.getenv("MYSQL_PORT")
DATABASE = os.getenv("MYSQL_DATABASE_NAME")

# 拼接数据库信息
DATABASE_URI = f"mysql+pymysql://{USER}:{PWD}@{HOST}:{PORT}/{DATABASE}"

# token信息
# 默认两小时
ACCOUNT_TOKEN_EXPIRES = int(os.getenv("ACCESS_TOKEN_EXPIRES", "7200"))
RERRESH_TOKEN_EXPIRES = int(os.getenv("ACCESS_TOKEN_EXPIRES", "7200"))


@dataclass
class Config:
    """配置"""

    FLASK_ENV = os.getenv("FLASK_ENV")
    SQLALCHEMY_DATABASE_URI = DATABASE_URI
    JWT_SECRET_KEY = os.getenv("SECRET_KEY")
    JWT_ACCESS_TOKEN_EXPIRES = timedelta(seconds=ACCOUNT_TOKEN_EXPIRES)
    JWT_REFRESH_TOKEN_EXPIRES = timedelta(days=ACCOUNT_TOKEN_EXPIRES)
    JWT_BLOCKLIST_TOKEN_CHECKS = ["access"]
    PROPAGATE_EXCEPTIONS = True
    # avatar上传配置
    UPLOADED_AVATAR_DEST = "assets/avatar"
    UPLOADED_AVATAR_URL = "avatar"
    UPLOADED_AVATAR_ALLOW = ["png", "jpg"]
    UPLOADED_AVATAR_MAX_SIZE = 2 * 1024 * 1024
    # 图片上传配置
    # 视频上传配置
    # 默认上传配置

    # UPLOADED_DEFAULT_DEST = "/assets"
    # UPLOADEDED_FILES_URL = '/assets'
    # UPLOADEDED_FILES_ALLOW = ['png', 'jpg', 'mp4']
    # UPLOADED_DEFAULT_MAX_SIZE = 16 * 1024 * 1024


@dataclass
class DevelopmentConfig(Config):
    """开发配置"""

    DEBUG = True


@dataclass
class ProductionConfig(Config):
    """生产配置"""

    DEBUG = False


@dataclass
class UploadConfig:
    avatar = UploadSet(name="avatar")


config = {
    "dev": DevelopmentConfig,
    "prd": ProductionConfig,
}
